package com.elephant.core.controller;

import com.elephant.core.controller.dao.DictMapper;
import com.elephant.core.controller.domain.Dict;
import com.elephant.core.utils.excel.ReadExcelForxlsx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author hai
 * @description
 * @date 18:10 2018/9/3
 */
@RestController
@RequestMapping("/elephant")
public class TkMapperController {

    private final static Logger logger = LoggerFactory.getLogger(TkMapperController.class);
    @Autowired
    private DictMapper dictMapper;


    static {
        System.setProperty("TestSystem","MyProperty");
    }

    @RequestMapping(value = "/tk", method = RequestMethod.GET)
    public Object tkMybatis(){
        System.out.println("11111111111111");
        List<Dict> list = dictMapper.selectAll();
        System.out.println("2222222222222222");
        return list;
    }

    @RequestMapping(value = "/tkV", method = RequestMethod.GET)
    public Object tkMybatisV(HttpServletRequest request){

        long time = System.currentTimeMillis();
        //spring 计时器
        StopWatch stopWatch = new StopWatch(request.getRequestURI() + "-" + time);
        stopWatch.start(request.getRequestURI() + "-" + time);
        Dict dict = new Dict();
        dict.setDictType("BundleIdMapper");
        List<Dict> list = dictMapper.select(dict);
        stopWatch.stop();
        logger.info("use time: \r\n" + stopWatch.prettyPrint());
        return list;
    }

    @Autowired
    private ReadExcelForxlsx readExcelForxlsx;

    @RequestMapping(value = "/excel/handle", method = RequestMethod.GET)
    public String doHandle(){
        readExcelForxlsx.handleExcel();
        return "success";
    }

    public static void main(String[] args) {

        System.out.println(System.getProperty("TestSystem"));
    }
}
